package com.edu.modules.baseinfo.api;

import com.alibaba.fastjson.JSONObject;
import com.edu.modules.baseinfo.service.TeacherService;
import com.edu.modules.baseinfo.vo.ResultVo;
import com.sari.common.utils.RequestContextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author kwj
 * @version 2016-08-01
 */
@CrossOrigin
@Controller
@RequestMapping(value = "teacher")
public class TeacherApi {

    @Autowired
    private TeacherService teacherService;

    @ResponseBody
    @RequestMapping(value = "save")
    public ResultVo saveTeacher(HttpServletRequest request){

        JSONObject param = RequestContextUtils.readJson(request);
        return teacherService.saveTeacher(param);
    }

    @ResponseBody
    @RequestMapping(value = "getTeacherByPage")
    public JSONObject getTeacherByPage(HttpServletRequest request) {

        JSONObject param = RequestContextUtils.readJson(request);
        return teacherService.getTeacherByPage(param);
    }

    @ResponseBody
    @RequestMapping(value = "getTeacherLessonStatistics")
    public JSONObject getTeacherLessonStatistics(HttpServletRequest request) {

        JSONObject param = RequestContextUtils.readJson(request);
        return teacherService.getTeacherLessonStatistics(param);
    }

    @ResponseBody
    @RequestMapping(value = "getTeacherClassStatistics")
    public JSONObject getTeacherClassStatistics(HttpServletRequest request) {

        JSONObject param = RequestContextUtils.readJson(request);
        return teacherService.getTeacherClassStatistics(param);
    }

    @ResponseBody
    @RequestMapping(value = "update")
    public ResultVo updateTeacher(HttpServletRequest request){

        JSONObject param = RequestContextUtils.readJson(request);
        teacherService.updateTeacher(param);
        return new ResultVo(true,"success");
    }

    @ResponseBody
    @RequestMapping(value = "delete")
    public ResultVo deleteTeacher(String teacherId) {

        return teacherService.deleteTeacher(teacherId);
    }

    @ResponseBody
    @RequestMapping(value = "getTeacherByLesson")
    public JSONObject getTeacherByLesson(String lesson) {

        return teacherService.getTeacherByLesson(lesson);
    }

    @ResponseBody
    @RequestMapping(value = "getTeachersLesson")
    public JSONObject getTeachersLesson(){

        JSONObject result = new JSONObject();
        result.put("teachers",teacherService.getTeachersLesson());
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "getTeacherName")
    public JSONObject getTeacherName(){

        JSONObject result = new JSONObject();
        result.put("teachers",teacherService.getTeacherName());
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "teacherEvaluate")
    public JSONObject getTeacherEvaluateByPage(HttpServletRequest request) {

        JSONObject param = RequestContextUtils.readJson(request);
        return teacherService.getTeacherEvaluateByPage(param);
    }

    @ResponseBody
    @RequestMapping(value = "deleteEvaluate")
    public ResultVo deleteEvaluate(String evaluateId){

        return teacherService.deleteEvaluate(evaluateId);
    }
}
